#ifndef LOGICHANDLER_H
#define LOGICHANDLER_H
#include "SingleClass.h"
#include <boost/beast/http.hpp>
#include "httpConnection.h"
#include <unordered_map>
#include <string>
#include <functional>
namespace http=boost::beast::http;

enum errorCodes{
    ERROR=0,
    SUCCESS=1,
};
class LogicHandler:public SingleClass<LogicHandler>{
public:
    
    //处理get请求与post请求
    void handler_get(const std::shared_ptr<httpConnection>& con); 
    void handler_post(const std::shared_ptr<httpConnection>& con); 
private:
    friend class SingleClass<LogicHandler>;   //为了能够执行get_instance里的new
    LogicHandler();

    //注册一系列的路由与对应的函数  key:是路由   value是对应业务处理函数
    std::unordered_map<std::string,std::function<void(const std::shared_ptr<httpConnection>& con)>> _get_handlers;
    std::unordered_map<std::string,std::function<void(const std::shared_ptr<httpConnection>& con)>> _post_handlers;

    //初始化路由与对应的函数
    void init_get_handlers();
    void init_post_handlers();

    //post请求对应的处理函数
        //----用户中心这块
    void doing_post_get_varifyCode(const std::shared_ptr<httpConnection>& con);
    void doing_post_register_user(const std::shared_ptr<httpConnection>& con);
    void doing_post_reset_passwd(const std::shared_ptr<httpConnection>& con);
    void doing_post_login(const std::shared_ptr<httpConnection>& con);
};

#endif